package com.epam.employeebase.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.BatchSize;

@Entity
@Table(name="employees")
@NamedQueries(
		{	@NamedQuery(name="list", query="from Employee"),
			@NamedQuery(name="count", query="select count(*) from Employee")
		})
public class Employee {
	private Long id;
	private String lastName;
	private String firstName;
	private Address address;
	private Set<Employment> employments = new HashSet<Employment>();
	
	@Id
	@SequenceGenerator(name="employeeGenerator", sequenceName="EMPLOYEES_SEQ")
	@GeneratedValue(generator="employeeGenerator")
	@Column(name="id")
	public Long getId() {
		return id;
	}
	public void setId(Long id){
		this.id = id;
	}
	@Column(name="LAST_NAME")
	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	@Column(name="FIRST_NAME")
	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	
	@OneToMany(mappedBy="employee", fetch=FetchType.EAGER)
	@BatchSize(size=100)
	public Set<Employment> getEmployments() {
		return employments;
	}

	public void setEmployments(Set<Employment> employments) {
		this.employments = employments;
	}
	
	@OneToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="address_id", unique=true)
	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}
}
